package client.comm.baoding.dialog

import android.view.View
import androidx.databinding.ObservableField
import androidx.fragment.app.FragmentActivity
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.DialogSelectpaytypeBinding
import client.comm.commlib.utils.StoreUtil
import client.tzstore.oo.dialog.BottomBindingDialog

/**
 * 支付方式 弹窗
 *
 * 1余额支付
 * 2分享积分
 * 3支付宝支付
 *
 */
class SelectPayTypeDialog(context: FragmentActivity) :
    BottomBindingDialog<DialogSelectpaytypeBinding>(context) {

    override fun getV(): Int {
        return R.layout.dialog_selectpaytype
    }

    var addrIndex = 0

    val income = ObservableField<String>("0")
    val integral = ObservableField<String>("0")
    val wallet_jin = ObservableField<String>("0")
    val wallet_pin = ObservableField<String>("0")
    val good_wallet_pin = ObservableField<Double>()

    override fun postBinding() {
        binding.event = this
        StoreUtil.getBean<UserInfo>(context)?.let {
            income.set("${it.income}")
            integral.set("${it.integral}")


            binding.btnYue.visibility =
                if (it.recharge_str.contains("1")) View.VISIBLE else View.GONE
            binding.btnAlipay.visibility =
                if (it.recharge_str.contains("3")) View.VISIBLE else View.GONE
            binding.btnSande.visibility =
                if (it.recharge_str.contains("7")) View.VISIBLE else View.GONE

//            wallet_jin.set("${it.integral_f}")
//            wallet_pin.set("${it.income_r}")

//            if (good_wallet_pin.get()!! > 0) {
//                binding.btnLpq.isVisible = true
//                binding.btnYue.isVisible = false
//                binding.btnAlipay.isVisible = false
////                binding.btnLjq.isVisible = false
//            } else {//普通商品，体验券隐藏
//                binding.btnYue.isVisible = true
//                binding.btnAlipay.isVisible = true
//                binding.btnLpq.isVisible = false
////                binding.btnLjq.isVisible = false
//            }
        }
    }

    var one: ((type: Int, txt: String) -> Unit)? = null

    fun oneType() {
        cancel()
        one?.invoke(1, "余额支付(余额:${income.get()}})")//,积分:${integral.get()
    }

    fun jfType() {
        cancel()
        one?.invoke(2, "积分支付(积分:${integral.get()})") //余额:${income.get()},
    }

    fun shareLjqType() {
        cancel()
        one?.invoke(2, context.getString(R.string.wallet_jin) + "(${wallet_jin.get()})")

    }

    fun alipayType() {
        cancel()
        one?.invoke(3, "支付宝支付")
    }

    fun sandeType() {
        cancel()
        one?.invoke(7, "杉德支付")
    }

    fun bankType() {
        cancel()
        one?.invoke(5, "快捷支付")
    }

}